package com.zzxx.wechat.controller;

import com.zzxx.wechat.common.vo.ArcteryxSwitchChangeReq;
import com.zzxx.wechat.common.vo.ArcteryxSwitchReq;
import com.zzxx.wechat.common.vo.ArcteryxSwitchVo;
import com.zzxx.wechat.result.R;
import com.zzxx.wechat.service.ArcteryxSwitchService;
import com.zzxx.wechat.service.ArcteryxTaskService;
import com.zzxx.wechat.util.ArcteryxSwitchConstants;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/arcteryx/switch")
public class ArcteryxSwitchController {



    @Resource
    private ArcteryxSwitchService arcteryxSwitchService;
    @Resource
    private ArcteryxTaskService arcteryxTaskService;

    @PostMapping("/status")
    @ResponseBody
    public R<ArcteryxSwitchVo> status() {
        ArcteryxSwitchReq req = new ArcteryxSwitchReq();
        req.setConfigName(ArcteryxSwitchConstants.CONFIG_SWITCH_NAME);
        ArcteryxSwitchVo arcteryxSwitchVo = arcteryxSwitchService.queryByConfigName(req);

        return R.ok(arcteryxSwitchVo);
    }

    @PostMapping("/change")
    @ResponseBody
    public R<Void> change(@RequestBody ArcteryxSwitchChangeReq req) {
        req.setConfigName(ArcteryxSwitchConstants.CONFIG_SWITCH_NAME);
        arcteryxSwitchService.changeByConfigName(ArcteryxSwitchConstants.CONFIG_SWITCH_NAME, req.getConfigSwitch() ? 1 : 0);

        arcteryxTaskService.asyncArcteryxJob();
        return R.ok();
    }


}
